package pers.vic.system.system.service;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import pers.vic.base.bo.system.SysArea;
import pers.vic.base.pager.Lookup;
import pers.vic.base.pager.PageInfo;
import pers.vic.base.service.BaseService;
import pers.vic.base.vo.BaseModel;
import pers.vic.system.system.mapper.SysAreaMapper;

/**
 * 区域表 Service
 * 
 * @author VIC
 */
@Service
public class SysAreaService extends BaseService {

	@Resource
	private SysAreaMapper sysAreaMapper;

	/**
	 * 查询列表
	 */
	public PageInfo<SysArea> list(Lookup lookup) {
		startPage(lookup);
		List<SysArea> datas = sysAreaMapper.list(lookup);
		return PageInfo.instance(datas, lookup);
	}

	/**
	 * 根据主键查询
	 */
	public SysArea findById(int id) {
		return sysAreaMapper.findById(id);
	}

	/**
	 * 根据主键数组查询
	 */
	public List<SysArea> findByIds(int... ids) {
		return sysAreaMapper.findByIds(ids);
	}

	/**
	 * 新增
	 */
	@Transactional
	public int insert(SysArea entity) {
		return sysAreaMapper.insert(entity);
	}

	/**
	 * 修改
	 */
	@Transactional
	public int update(SysArea entity) {
		return sysAreaMapper.update(entity);
	}

	/***
	 * 删除
	 */
	@Transactional
	public int delete(int... ids) {
		return sysAreaMapper.delete(ids);
	}
	
	/** 全部的省 */
	public List<BaseModel> provinces() {
		return sysAreaMapper.provinces();
	}
	
	/**
	 * 获得子区域
	 */
	public List<BaseModel> findChildren(int parentId){
		return sysAreaMapper.findChildren(parentId);
	}
	/**全部开发的城市*/
	public List<BaseModel> opendCityList() {
		return sysAreaMapper.opendCityList();
	}
	/**
	 * 查询id 根据名称和层级
	 * @param name
	 * @param level层级:0国家级别，1省级，2地市级，3区县级
	 * @return
	 */
	public Integer findByNameAndLevel(String name, int level){
		if(StringUtils.isEmpty(name)) {
			return null;
		}
		return sysAreaMapper.findByNameAndLevel(name, level);
	}

}
